{include file="head_2" title="友情链接" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <div class="page_menu"><a href="/admin/links/add.html" ><button class="layui-btn layui-btn-primary">添加</button></a></div>
            <div style="clear:both"></div>
            <table class="layui-table" lay-data="{ url:'/admin/links/get_josn/', page:false, id:'idTest'}" lay-filter="demo">
                <thead>
                    <tr>
                        <th lay-data="{field:'id',align:'center', width:80}">编号</th>
                        <th lay-data="{field:'name',align:'center', width:150}">链接名称</th>
                        <th lay-data="{field:'url',align:'center', width:280}">链接</th>
                        <th lay-data="{field:'sort',align:'center', width:100}">排序</th>
                        <th lay-data="{field:'status', align:'center', width:100}">状态</th>
                        <th lay-data="{field:'date', align:'center', width:150}">发布时间</th>
                        <th lay-data="{fixed: 'right', width:150, align:'left', toolbar: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>

        </div>
    </div>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>

<script>
    layui.use(['layer', 'table', 'jquery'], function () {
        var layer = layui.layer //弹层
                , table = layui.table //表格
                , $ = layui.$;

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data
                    , layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    del_data(obj);
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if (layEvent === 'edit') {
                location.href = "/admin/links/edit/id/" + data.id;
            }
        });
        function del_data(obj)
        {
            var data = obj.data;
            $.ajax({
                url: "/admin/links/del_submit/",
                type: 'post',
                data: {id: data.id},
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1)
                    {
                        layer.msg("删除成功!", {
                            time: 2000
                        }, function () {
                            location.reload();
                        });
                    } else
                    {
                        layer.msg(data.msg);
                    }
                },
            });
        }

    });
</script>
{include file="foot" /}